package cn.xiaosiyuan.util.path;

import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.xiaosiyuan.util.interfaces.IPathUtil;

public class PathUtil implements IPathUtil {
    /**
     *
     */
    public String getByRelativePath(String relativePath) {
        String rs = "";

        try {
            // hutool 的实现
            rs = ResourceUtil.getResource("").getPath();
            if (rs.startsWith("/")) {
                rs = rs.substring(1);
            }

            // 如果想对路径有斜杠或反斜杠
            if (relativePath.startsWith("/") || relativePath.startsWith("\\")) {
                rs += relativePath;
            } else {
               rs += "/" + relativePath;
            }
        } catch (IORuntimeException e) {
            e.printStackTrace();
        }

        return rs;
    }
}
